fetchInject(["./quran.js"]);
document.addEventListener('keydown', keydownEventHandler);
document.getElementsByName('surah_text')[0].innerHTML = quranjson[0].join("");
function keydownEventHandler(e){
    switch (e.key){
        case 'Enter':
            document.getElementsByName('surah')[0].focus();
            break;
        case 'ArrowRight':
            var next = document.activeElement.tabIndex + 1;
            if (next > document.getElementsByName('a').length - 1){
                next = 0;
            }
            document.getElementsByName("a")[next].focus();
            break;
        case 'ArrowLeft':
            var prev = document.activeElement.tabIndex - 1;
            if (prev == -1){
                prev = document.getElementsByName('a').length - 1;
            }
            document.getElementsByName("a")[prev].focus();
            break;
        case 'SoftLeft':
            var elm = document.getElementsByName('licence')[0];
            window.alert(elm.innerHTML);
            break;

    }
}
document.getElementsByName('surah')[0].onchange = function (){
    document.getElementsByName('licence')[0].style.display = "none";
    var index = Number(document.getElementsByName('surah')[0].value) - 1;
    var surah_text = document.getElementsByName('surah_text')[0];
    surah_text.innerHTML = '';
    var surah_array = quranjson[index];
    var i = 0;
    for (;i < surah_array.length; i++){
        if ((i%10) == 0){
            var div  = '<div name="a" tabIndex="$"></div>';
            div = div.replace("$", String(i/10));
            surah_text.innerHTML += div;
        }
        surah_text.innerHTML += surah_array[i];
    }
    surah_text.innerHTML += '<div name="a" tabIndex="'+String(i/10
    +1)+'"></div>';
    document.getElementsByName("a")[0].focus();
}
